import datarover from "../../../lib/datarover.mjs";

/**
 * 渲染日期时间格式
 * @param {HTMLElement} td - 单元格元素
 * @param {Object} col - 列配置
 */
export function renderDateTime(td, col) {
  let value = datarover(td, col.col);
  value = value?.replace(/\//g, "-");
  let date = new Date(`${value}`);

  if (!isNaN(date.getTime())) {
    const utcValue = Date.UTC(
      date.getFullYear(),
      date.getMonth(),
      date.getDate(),
      date.getHours(),
      date.getMinutes(),
      date.getSeconds(),
      date.getMilliseconds()
    );
    td.innerText = new Intl.DateTimeFormat(
      "default",
      // "en-GB",
      // "en-US",
      col.DateTimeFormat
    ).format(utcValue);
  }
}
